#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stdio.h"
#include "graphics.h"
#include "osg.h"
#include "gui_osd.h"
#include "stddef.h"

#include "dbgprint.h"
#include "ColorChange.h"
#include "ui_common.h"
#include "color.h"
#include "ostask.h"

#if 0
void UI_DrawBmp(int x,int y,int w,int h,UCHAR* bmpdata)
{
    D_OSD_DrawMap( x, y,w,h,w,h,0,0,0,0,bmpdata,2,PIX_MAP_MODE_1555bits);
}
#endif

typedef enum OSD_ColorType_e
{
	OSD_COLOR_TYPE_ARGB8888,
	OSD_COLOR_TYPE_RGB888,
	OSD_COLOR_TYPE_ARGB8565,
	OSD_COLOR_TYPE_RGB565,
	OSD_COLOR_TYPE_ARGB1555,
	OSD_COLOR_TYPE_ARGB4444,

	OSD_COLOR_TYPE_CLUT8,
	OSD_COLOR_TYPE_CLUT4,
	OSD_COLOR_TYPE_CLUT2,
	OSD_COLOR_TYPE_CLUT1,
	OSD_COLOR_TYPE_ACLUT88,
	OSD_COLOR_TYPE_ACLUT44,

	OSD_COLOR_TYPE_SIGNED_YCBCR888_444,
	OSD_COLOR_TYPE_UNSIGNED_YCBCR888_444,
	OSD_COLOR_TYPE_SIGNED_YCBCR888_422,
	OSD_COLOR_TYPE_UNSIGNED_YCBCR888_422,
	OSD_COLOR_TYPE_SIGNED_YCBCR888_420,
	OSD_COLOR_TYPE_UNSIGNED_YCBCR888_420,
	OSD_COLOR_TYPE_UNSIGNED_AYCBCR6888_444,
	OSD_COLOR_TYPE_SIGNED_AYCBCR8888,
	OSD_COLOR_TYPE_UNSIGNED_AYCBCR8888,

	OSD_COLOR_TYPE_ALPHA1,
	OSD_COLOR_TYPE_ALPHA4,
	OSD_COLOR_TYPE_ALPHA8,
	OSD_COLOR_TYPE_BYTE,

	OSD_COLOR_TYPE_ARGB8888_255,
	OSD_COLOR_TYPE_ARGB8565_255,
	OSD_COLOR_TYPE_ACLUT88_255,
	OSD_COLOR_TYPE_ALPHA8_255

} OSD_ColorType_t;

#define GAMMA_FILE_RGB565           0x80
#define GAMMA_FILE_RGB888           0x81
#define GAMMA_FILE_ARGB8888         0x85
#define GAMMA_FILE_ARGB1555         0x86
#define GAMMA_FILE_ARGB4444         0x87
#define GAMMA_FILE_ACLUT8           0x8B
#define GAMMA_FILE_ACLUT44          0x8C
#define GAMMA_FILE_ACLUT88          0x8D
#define GAMMA_FILE_CLUT8            0x8E
#define GAMMA_FILE_YCBCR422R        0x92
#define GAMMA_FILE_AYCBCR8888       0x96
#define GAMMA_FILE_A1               0x98

#if 0//not used hide by jl
/* parameters of Bitmap */
typedef struct GUTIL_GamHeader_
{
    U16 Signature;      /* usualy 0x444F       */
    U16 Type;           /* See previous define */
    U16 Properties;     /* Usualy 0x0          */
    U32 zero;           /* Usualy 0x0          */
} GUTIL_GamHeader;
static U8  ViewPortNb = LAYER_OSD;

#endif

extern U8 OsdGetViewPortNb(void);
extern void OsdSetViewPortNb(U8 ViewPortNb_p);
extern void OsdSetLayerNb(U8 LayerNb_p);
extern void GuiColorInit(void);
//extern void GUTIL_SetGamHeader(GUTIL_GamHeader Gamma_Header);
extern void SetOsdColorType(OSD_ColorType_t osdcolortype);

void OSGInitialize(void)
{
	int err;
	LOGD("slq test OSGInitialize is start\n");
	err = init_graph();
	if (err != OK) {
              LOGE("init_graph err=%d\n", err);
		return;
	}
	LOGD("init_graph is ok\n");

}

E_ERR_CODE OSGClose(void)
{
    E_ERR_CODE Err = OK;

    Err = close_graph();
    if(Err != OK)
    {
        LOGE("close_graph is err\n");
    }

    return Err;
}

void osdtest(void)
{
	//int i;
       LOGD("-----ooo\n");

#if 1
	OSGInitialize();
	UI_FillRectangle(400, 100, 200, 300, 0x8567);
	Os_ThreadDelayMs(5000);
	//D_OSD_FillRectangle(100, 100, 400, 400, 0x80ff0000);
	close_graph();
#endif
}

void OSGSetColorType(OSD_ColorType_t mode)
{
#if 0
    GUTIL_GamHeader Gamma_Header_;

    switch(mode)
    {
        case OSD_COLOR_TYPE_ARGB8888:
        {
            Gamma_Header_.Signature = 0x444F;
            Gamma_Header_.Type = GAMMA_FILE_ARGB8888;
            Gamma_Header_.Properties = 0;
            Gamma_Header_.zero = 0;

            GUTIL_SetGamHeader(Gamma_Header_);
            SetOsdColorType(mode);
            global_alpha=0x80;
            break;
        }
        case OSD_COLOR_TYPE_ARGB1555:
        {
            Gamma_Header_.Signature = 0x444F;
            Gamma_Header_.Type = GAMMA_FILE_ARGB1555;
            Gamma_Header_.Properties = 0;
            Gamma_Header_.zero = 0;

            GUTIL_SetGamHeader(Gamma_Header_);
            SetOsdColorType(mode);
            global_alpha = 1;
            break;
        }
        case OSD_COLOR_TYPE_ARGB4444:
        {
            Gamma_Header_.Signature = 0x444F;
            Gamma_Header_.Type = GAMMA_FILE_ARGB4444;
            Gamma_Header_.Properties = 0;
            Gamma_Header_.zero = 0;

            GUTIL_SetGamHeader(Gamma_Header_);
            SetOsdColorType(mode);
            global_alpha=0xf;
            break;
        }
        case OSD_COLOR_TYPE_RGB565:
        {
            Gamma_Header_.Signature = 0x444F;
            Gamma_Header_.Type = GAMMA_FILE_RGB565;
            Gamma_Header_.Properties = 0;
            Gamma_Header_.zero = 0;

            GUTIL_SetGamHeader(Gamma_Header_);
            SetOsdColorType(mode);
            global_alpha=0;
            break;
        }
        default:

            break;
    }
#endif
}

int OSGHideOSD(void)
{
    HideOSD();
    return 0;
}

int OSGDisplayOSD(void)
{
    DisplayOSD();
    return 0;
}

void VID_DisableOutputWindow(void)
{
//STVID_DisableOutputWindow(VID_ViewPortHandle_Multiple[0]);
}

#ifdef UI_HD
void Vout_Enable(void)
{
    //STVOUT_Enable(VOUT_Handler[0]);
}

void Vout_Disable(void)
{
    //STVOUT_Disable(VOUT_Handler[0]);
}
#endif
/*
OSD  and STILL display
TV_480I     OSGSwitchType 1
TV_480P     OSGSwitchType 2
TV_576I     OSGSwitchType 3
TV_576P     OSGSwitchType 4
TV_720I     OSGSwitchType 5
TV_720P     OSGSwitchType 6
TV_1080I        OSGSwitchType 7
TV_1080P    OSGSwitchType 8
 //
VTG_1080I_7250(Australian Modes)
VTG_576I_50S
VTG_480I_60S, VTG_480I_59S
VTG_1152I_4850(Australian Modes)
*/
//add by  for mode of osd and still display
BOOL ViewPortFilterFlag = TRUE;
static char showIframe_flag = FALSE;



int GetshowIframe_flag(void)
{
   return  showIframe_flag;
}

void SetshowIframe_flag(int flag)
{
    showIframe_flag = flag;
}



